<?php
namespace App\Models\Factory;
use App\Models\AbsModelFactory;
use App\Models\Orm\Cap_call_log;
use App\Models\Orm\Cap_mon_bill;
use App\Models\Orm\Cap_SMS_log;
use App\Models\Orm\Cap_user;
use App\Models\Orm\CapCallLog;
use App\Models\Orm\CapMonBill;
use App\Models\Orm\CapSMSLog;

/**
 *
 * Class CapFactory
 * @package App\Models\Factory
 */
class CapFactory extends  AbsModelFactory
{

    //往运营商的用户表插入用户
    public static function adduser($data){
        $time = date("Y-m-d H:i:s",time());
        $data['created_at'] = $time;
        $res = Cap_user::firstOrCreate(['uid'=>$data['uid']],$data);
        return $res? true :false;
    }

    //往运营商的通话记录表里插入数据
    public static function addcall_log($data,$uid){

        //查看生成的数组大小
        $i = count($data);
        if($i){

            foreach($data as $call){
                $call['uid'] = $uid;
                $time = date("Y-m-d H:i:s",time());
                $call['created_at'] = $time;
                $res = CapCallLog::insert($call);
                if(!$res){
                    continue;
                }
            }
            $call_log = CapCallLog::all()->first();
           return  empty($call_log)? false :true;
        }
    }

    //运营商短信发送表里添加数据
    public static function addSMS_log($data,$uid)
    {

        //查看生成数组大小
        $i = count($data);
        if($i) {

            foreach($data as $sms){
                $sms['uid'] = $uid;
                $time = date("Y-m-d H:i:s",time());
                $sms['created_at'] = $time;
                $res = CapSMSLog::insert($sms);
                if(!$res){
                    continue;
                }
            }
            $sms_log = CapSMSLog::all()->first();
           return  empty($sms_log)? false :true;
        }


    }

    //运营商月账单里添加数据
    public static function addcapmon_bill($data,$uid)
    {
        //查看生成数组大小
        $i = count($data);
        if($i) {

            foreach($data as $mon){
                $mon['uid'] = $uid;
                $time = date("Y-m-d H:i:s",time());
                $mon['created_at'] = $time;
                $res = CapMonBill::insert($mon);
                if(!$res){
                    continue;
                }
            }

        }
        $mon_log = CapMonBill::all();
        empty($mon_log )? false :true;
    }

}